package com.vince.hulk.mechanism
{
import com.vince.hulk.character.Character;
import com.vince.hulk.states.PlayState;

import org.flixel.FlxG;
import org.flixel.FlxSprite;

/**
 * author yangwz
 */		
public class GameButton extends FlxSprite implements IMechanism
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	/**
	 * Constructs a new <code>GameButton</code> instance.
	 * 
	 */
	public function GameButton(X:Number=0, Y:Number=0, imech:IMechanism = null, activate_size:int = 0)
	{
		mech = imech;
		super(X, Y, null);
		activated = false;
		activateSize = activate_size;
		addAnimation("idle", [0], 0, false);
		addAnimation("active", [1], 0, false);
		immovable = true;
		allowCollisions = ANY;
	}
	//==========================================================================
	//  Variables
	//==========================================================================
	private var img:Class;
	private var activated:Boolean;
	private var mech:IMechanism;
	private var activateSize:int;
	private var activatingCharacter:Character;
	//==========================================================================
	//  Methods
	//==========================================================================
	public function activate(character:Character):void
	{
		var state:PlayState = null;
		if (character.size() >= activateSize && !activated && isTouching(UP))
		{
			state = FlxG.state as PlayState;
			state.buttonPairs[this] = character;
			play("active");
			activated = true;
			mech.activate(character);
		}
	}
	
	/**
	 * 关闭 
	 * 
	 */	
	public function deactivate() : void
	{
		play("idle");
		mech.activate(activatingCharacter);
		activated = false;
	}
	
	public function isActivated() : Boolean
	{
		return activated;
	}
	
	public function toggle():void
	{
	}
}
}